package com.familytreemangement.controller;

import com.familytreemangement.common.Result;
import com.familytreemangement.controller.request.UserPageRequest;
import com.familytreemangement.entity.User;
import com.familytreemangement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


//    public List<User> listUsers(){
//       //前端现实的
//        return userService.findAll();
//    }
    @GetMapping("/list")
    public Result list(){
        //连不了前端的
        //List<User> users = userService.findAll();
         List<User> users = userService.list();
        return Result.success(users);
    }
    @GetMapping("/page")
    public Result page(UserPageRequest  userPageRequest){
        return Result.success(userService.page(userPageRequest));
    }
}
